package com.system.travel.modules.system.controller;

import com.system.travel.common.response.Result;
import com.system.travel.common.utils.SecurityUtils;
import com.system.travel.modules.system.entity.SysUser;
import com.system.travel.modules.system.service.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    
    @Resource
    private SysUserService userService;
    
    @GetMapping("/info")
    public Result<Map<String, Object>> getUserInfo() {
        try {
            // 从SecurityContext中获取当前登录用户
            String username = SecurityUtils.getUsername();
            SysUser user = userService.getByUsername(username);
            
            if (user == null) {
                return Result.error("用户不存在");
            }
            
            // 获取用户详细信息
            Map<String, Object> userInfo = userService.getUserInfo(user.getId());
            return Result.success(userInfo);
        } catch (Exception e) {
            return Result.error("获取用户信息失败：" + e.getMessage());
        }
    }
} 